import request from '@/utils/request'
import { BaseResponse } from '../base'

export function detail(id: number): Promise<BaseResponse> {
  return request({ url: `/campus/address/detail/${id}`, method: 'get' })
}

export function addAddress(data: any): Promise<BaseResponse> {
  return request({ url: '/campus/address/add', method: 'post', data })
}

export function addOrUpdateAddress(data: any): Promise<BaseResponse> {
  if (data.id) {
    return updateAddress(data)
  } else {
    return addAddress(data)
  }
}

export function updateAddress(data: any): Promise<BaseResponse> {
  return request({ url: '/campus/address/update', method: 'put', data })
}

export function deleteAddress(id: number): Promise<BaseResponse> {
  return request({ url: `/campus/address/delete/${id}`, method: 'detele' })
}

export function setDefault(id: number): Promise<BaseResponse> {
  return request({ url: `/campus/address/default/${id}`, method: 'put' })
}

export function getDefault(): Promise<BaseResponse> {
  return request({ url: `/campus/address/getAddress`, method: 'get' })
}

export function list(): Promise<BaseResponse> {
  return request({ url: `/campus/address/list`, method: 'get' })
}